<template>
	<view class="home">
		<list-scroll class="list-scroll" @load="load">
			<list-card :list="list" :item="item" v-for="item in list"></list-card>
		</list-scroll>
		<view v-if="isload" class="cu-load loading"></view>
		<view class="kong" v-if="show">
			<image src="../../static/img/空.png"></image>
		</view>
		<tabbar></tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				show: false,
				num: 0,
				page: 0,
				limit: 10,
				isload: false,
				shu: 0
			}
		},

		methods: {
			onLoad() {
				uni.showLoading()
				setTimeout(()=>{
					uni.hideLoading()
				},1000)
			},
           

		
			load() {
				this.isload = true
				setTimeout(() => {
					this.page = this.page + this.limit

					this.init(this.page)
				}, 1000)


			},
			onPullDownRefresh() {
				this.init()
			},
			async init() {
				let res = await uniCloud.callFunction({
					name: "get_content",
					data: {
						type: "ok", //已经审核通过的帖子
						page: this.page,
						limit: this.limit
					}
				})

				if (res.result.data) {
					this.list = this.list.concat(res.result.data)
					this.isload = false
					console.log(this.list);

				}

				if (!this.list.length) {
					this.show = true
				}

				this.login = uni.getStorageSync('islogin')
				if (this.login) { //登录了

					let info = uni.getStorageSync('userPhone') || uni.getStorageSync('userWx');
					this.info = info
					let res = await uniCloud.callFunction({
						name: "admin",
						data: {
							type: "checkadmin",
							id: info.id
						}
					})
					await this.$store.dispatch('initmsgnum', info.id) //获取消息通知数量
					await this.$store.dispatch('initchecknum') //获取审核帖子数量
					this.num = parseInt(this.$store.state.msg.length) + res.result.data[0].admin ? parseInt(this.$store.state.checknum
						.result.affectedDocs) : 0
					this.$store.commit('initnum', this.num)

					uni.stopPullDownRefresh()
				}
			}
		},

		async onShow() {
			this.$nextTick(function() {
				this.init()
			})

		}
	}
</script>
<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;

		.list-scroll {
			height: 100%;
		}
	}

	// .li{
	// 	display: none;
	// }
	.kong {
		position:fixed;
		top: 27%;
		left: 13%;
	}
</style>
